<!DOCTYPE html>
<html>
<head>
	<!-- 公共页面 -->
	#include("../include/common.html")
	<!-- 公共页面 /-->
</head>
<body class="hold-transition skin-purple sidebar-mini">
    <div class="wrapper">
        <!-- 页面头部 -->
        #include("../include/header.html")
        <!-- 页面头部 /-->

        <!-- 导航侧栏 -->
        #include("../include/menu.html")
        <!-- 导航侧栏 /-->

        <!-- 内容区域 -->
        <div class="content-wrapper" id="contentDiv">
            <!-- 正文区域 -->
            <section class="content">
				<!-- .box-body -->
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title">栏目管理</h3>
                    </div>
                    <div class="box-body">
                        <!-- 数据表格 -->
                        <div class="table-box">
                            <!--工具栏-->
                            <div class="pull-left">
                                <div class="form-group form-inline">
                                    <div class="btn-group">
                                        <button type="button" class="btn btn-default" onclick='location.href="#(base)/admin/category/add"'><i class="fa fa-file-o"></i> 新建</button>
                                        <button type="button" class="btn btn-default" id="refreshButton"><i class="fa fa-refresh"></i> 刷新</button>
                                        <button type="button" class="btn btn-default" id="sortButton" url="#(base)/admin/category/updateSort"><i class="fa fa-sort"></i> 排序</button>
                                    </div>
                                </div>
                            </div>
                            <!--工具栏/-->
                            <!--数据列表-->
                            <table id="listTable" class="table table-bordered table-striped table-hover dataTable">
                                <thead>
                                    <tr>
	                                    <th>ID</th>
	                                    <th>名称</th>
	                                    <th>URL目录</th>
	                                    <th>模型</th>
	                                    <th>列表页模板</th>
	                                    <th>详情页模板</th>
                                        <th width="40">排序</th>
	                                    <th>状态</th>
	                                    <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody id="listTr">
                                	#for(category : categoryTree)
	                                <tr>
	                                	<td>#(category.id)</td>
										<td>
											<span style="margin-left: #(category.grade * 20)px;#if(category.grade == 0) color: #000000;#end">
												#(category.name)
											</span>
										</td>
										<td>#(category.cat)</td>
										<td>#(category.model.name)</td>
										<td>#(category.listTemplate)</td>
										<td>#(category.detailTemplate)</td>
	                                    <td><input type="text" class="form-control" name="sorts" value="#(category.sort)" data-oldsort="#(category.sort)" data-id="#(category.id)"/></td>
										<td><input type="checkbox" class="js-switch-small switchbox" #if(category.status==1) checked #end data-id="#(category.id)" data-url="#(base)/admin/category/updateStatus"/></td>
										<td>
											<button type="button" class="btn bg-olive btn-xs" onclick='location.href="#(base)/admin/category/edit?id=#(category.id)"'>编辑</button>
                                            <button type="button" class="btn bg-olive btn-xs delete" val="#(category.id)">删除</button>
										</td>
									</tr>
	                                 #end
                                </tbody>
                            </table>
                            <!--数据列表/-->
                        </div>
                        <!-- 数据表格 /-->
                    </div>
                    <!-- /.box-body -->
                </div>
            </section>
            <!-- 正文区域 /-->
        </div>
        <!-- 内容区域 /-->
        <!-- 底部导航 -->
        #include("../include/footer.html")
        <!-- 底部导航 /-->
    </div>
</body>
</html>
<!---->
<script>
 $(document).ready(function() {
     // 激活导航位置
     setSidebarActive("admin-category");
 });
</script>
<script type="text/javascript">
var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch-small'));
elems.forEach(function(html) {
  var switchery = new Switchery(html, { size: 'small' });
});
$().ready(function() {

	var $delete = $("#listTable button.delete");
	
	// 删除
	$delete.click(function() {
		var $this = $(this);
		var id = $this.attr("val");
		swal({
		    title: '',
		    text:'确定要删除吗?',
		    icon: "warning",
		    buttons: {
		        cancel: "取消",
		        confirm: "确定"
		    }
		}).then(function(isConfirm){
			if(isConfirm){
				$.ajax({
					url: "#(base)/admin/category/delete",
					type: "POST",
					data: {id: id},
					dataType: "json",
					cache: false,
					success: function(response) {
						if (response.type == "success") {
							swal({title:'', text:'操作成功',icon: 'success',button:false,timer: 2000}).then(function(){
								$this.closest("tr").remove();
							});
						}else{
							swal({title:'', text:response.msg,icon: 'error'});
						}
					}
				});
			}
		});
	});

});
</script>